package GUIMain;

import java.awt.Component;
import java.io.File;

import javax.swing.JFileChooser;

import data.FilePath;

/**
 * Opens a file dialog and stores the link for future retrieval
 * @author Jonathan
 *
 */
public class FileChooser{
	private static JFileChooser jfc;
	private static File selectedFile;
	private static boolean initalized;
	
	public static void initialize(){
		initalized = true;
		jfc = new JFileChooser();
		jfc.setCurrentDirectory(new File(FilePath.DIRECTORY));

	}
	public static void openFileChooser(Component parent, boolean directoryOnly)
	{
		if(!initalized)
			initialize();
		if(directoryOnly){
			jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		}else{
			jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		}
		selectedFile = null;
		int result = jfc.showDialog(parent, "Select File");
		if(result == JFileChooser.APPROVE_OPTION){
			selectedFile = jfc.getSelectedFile();
		}
	}
	//Hides file chooser
	public static void closeFileChooser(){
	}
	public static boolean isVisible(){
		return jfc.getParent().isVisible();
	}
	public static File getSelectedFile(){
		return selectedFile;
	}
}
